package TUILayer;
import java.util.Scanner;
import ControllerLayer.*;


public class MainIIUI
{

    public MainIIUI(){
        selectMenu();
    }
    
    private int MainMenu()
    {      
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** Main Menu ***");
            System.out.println(" (1) Stock menu");
            System.out.println(" (2) ToolStock menu");
            System.out.println(" (3) Create new user");
            System.out.println(" (4) Exit");
            System.out.print("\n Make your choice: ");
            
            int choise = keyboard.nextInt();
            
            return choise;
    }
    
    private void selectMenu(){
        boolean exit = false;
       while(!exit)
       {
          int choise = MainMenu(); 
              if(choise == 1){
                   new StockUI().start();
              }  
              else{
                  if(choise == 2){
                     new ToolStockUI().start();
                  }  
                  else{
                      if(choise==3){
                          createNewUser();
                        }
                    
                        else{
                             exit = true;
                        }
                        }
                    }
                }
    }
       
    private void createNewUser()
    {UserController userController = new UserController();
        String name= inputName();
        String id=inputID();
        if(userController.findUser(id)==null)
        {
            String password= inputPassword();
            String password2=inputPasswordAgain();
            if(password.equals(password2))
            {
                boolean ok=false;
                while(!ok)
                {
                String answer=inputIsManager();
                if(answer.equals("m"))
                {
                    userController.addManager(id,password, name);
                    ok=true;
                }
                else
                if (answer.equals("a"))
                {
                    userController.addAssistant(id,password,name);
                    ok=true;
                }
                else
                {
                    System.out.println("Type m or n");
                }
            }
        }
        else
        {System.out.println("Password missmatch");
        }
    }
}
            
    
    private String  inputID()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type new ID: ");
        String address = keyboard.nextLine();
        return address;
    }
    
    
    private String  inputPassword()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type new password: ");
        String address = keyboard.nextLine();
        return address;
    }
    
    
    
    private String  inputPasswordAgain()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type again the password: ");
        String address = keyboard.nextLine();
        return address;
    }
    
    
    
    private String  inputName()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type name: ");
        String address = keyboard.nextLine();
        return address;
    }
    
    
    
    private String  inputIsManager()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Will the user be manager or user? type m for manager and a for assistant: ");
        String address = keyboard.nextLine();
        return address;
    }
}